<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <div id="app">
        <h3>日常工作列表</h3>
        <input type="text" v-model="uu" @keyup.enter="submit" />
        <button @click="addwork">添加</button>
        <ul v-for="(item,index) in list">
            <li>{{item.id}}{{item.work}} <button @click="delFunc(index)">×</button></li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                uu: "",
                list: [{
                    "id": 1,
                    "work": "吃饭"
                }, {
                    "id": 2,
                    "work": "睡觉"
                }, {
                    "id": 3,
                    "work": "打豆豆"
                }, ]
            },
            methods: {
                addwork: function() {
                    //添加函数
                    var myid = this.list.length;
                    this.list.push({
                        "id": myid + 1,
                        "work": this.uu
                    });
                    this.uu = '';
                },
                delFunc: function(index) {
                    confirm("确认要删除么？") && this.list.splice(index, 1);

                },
                submit: function() {
                    this.addwork()

                }
            }
        })
    </script>
</body>

</html>